using System;
using System.Collections.Generic;
using System.Text;

using miciv;
using micivCore.Data;

namespace micivCore.DataSource
{
    public class UnitTechniqueDataSource : DataSourceBase<IUnitTechnique>
    {
        protected IUnit m_unit;
        public IUnit Unit
        {
            get
            {
                return this.m_unit;
            }
            set
            {
                if (value != this.m_unit)
                {
                    this.m_unit = value;
                }
            }
        }

        public UnitTechniqueDataSource()
        {
        }

        override public T GetData<T>(int _sSourceIndex, string _strFieldName)
        {
            if (this.m_unit.Techniques.Count > _sSourceIndex)
            {
                switch (_strFieldName)
                {
                    case "name":
                    {
                        StringInfo si = this.m_unit.Techniques[_sSourceIndex].Text as StringInfo;
                        if (null != si)
                        {
                            return si.Text as T;
                        }
                        break;
                    }
                    case "fontid":
                    {
                        StringInfo si = this.m_unit.Techniques[_sSourceIndex].Text as StringInfo;
                        if (null != si)
                        {
                            return si.FontID as T;
                        }
                        break;
                    }
                    case "icon":
                    {
                        return this.m_unit.Techniques[_sSourceIndex].Icon as T;
                    }
                    case "unit":
                    {
                        return this.m_unit.ID as T;
                    }
                    case "unittechnique":
                    {
                        return this.m_unit.Techniques[_sSourceIndex].ID as T;
                    }
                }
            }
            return default(T);
        }

        override public void Update()
        {
            base.Update();
            foreach (IUnitTechnique technique in this.m_unit.Techniques)
            {
                this.Add(technique);
            }
        }
    }
}
